package asteroids.model.programs.parsing.expressions;

import java.util.Map;

import asteroids.model.CollisionObject;
import asteroids.model.Ship;

public class Variable extends BasicExpression {
	public Variable(String variable){
		setContent(variable);
	}
	
	public void setContent(String variable){
		this.content =variable;
	}
	
	public Object getContent(Map<String,E> map, CollisionObject givenCollisionObject){
		setMap(map);
		try{
		setCollisionObject(givenCollisionObject);
		return map.get(content).getContent(map, givenCollisionObject);
		}
		catch(NullPointerException exc){
			System.out.println("This variable is not initialized, please enter a new program.");
			if(givenCollisionObject.isShip()){
				Ship ship = (Ship)givenCollisionObject;
				ship.getProgram().setMistake();
			}
			return "";
		}
	}
	
	private String content;
	
	public boolean isString(){
		return true;
	}
	public boolean isDouble() {
		return false;
	}
	public boolean isBoolean(){
		return false;
	}
	public boolean isEntity(){
		return false;
	}
	
	public void setMap(Map<String,E> map){
		this.globals = map;
	}
	
	public void setExpression(E e){
		this.expression = e;
	}
	public E getExpression(){
		return this.expression;
	}
	private E expression;
	public String toString(){
		String content = getContent(globals, collisionObject) + "";
		return content;
	}
	public void setCollisionObject(CollisionObject collisionObject){
		this.collisionObject =collisionObject;
	}
	private Map<String,E> globals;
	private CollisionObject collisionObject;
}
